package com.bw.server.model

import com.blankj.utilcode.util.GsonUtils
import com.blankj.utilcode.util.NetworkUtils
import com.bw.common.entity.BaseRes
import com.bw.server.api.ServerApiService
import com.bw.server.entity.AddDeviceEntity
import com.bw.server.entity.AddDeviceEntityNull
import com.bw.server.entity.DetailDeviceEntity
import com.bw.server.entity.DeviceEntityItem
import com.bw.server.entity.DeviceStartEntity
import com.bw.server.entity.TransferInspectionEntity
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody
import javax.inject.Inject

class ServerRepository @Inject constructor(private val apiService: ServerApiService) {

    //列表
    suspend fun loadDeviceData():BaseRes<List<DeviceEntityItem>>{
        return if (NetworkUtils.isAvailable()){
            apiService.getDevice()
        }else{
            BaseRes(400, emptyList(),"当前没有网络！")
        }
    }

    //添加
    suspend fun loadAddDeviceData(body:AddDeviceEntityNull):BaseRes<AddDeviceEntity>{
        return apiService.getAddDevice(body)
    }

    //列表详情
    suspend fun loadDetailData(id:Int):BaseRes<DetailDeviceEntity>{
        return apiService.getDetailDevice(id)
    }

    //开始巡检
    suspend fun loadStartInspectionData(id:Int):BaseRes<DeviceStartEntity>{
        return apiService.startInspection(id)
    }

    //转派
    suspend fun loadTransferInspectionData(id:Int,inspector:String):BaseRes<TransferInspectionEntity>{
        return apiService.transferInspection(id,inspector)
    }
}